#!/bin/sh
username="zplay"
password="zplay888"
mails=$1
mysql_stat_log=mysql_monitor.log
if [ ! -f $mysql_stat_log ]; then
	touch $mysql_stat_log
fi
server_list_file=mysql_server.list
if [ ! -f $server_list_file ]; then
	echo "`date '+%Y-%m-%d %H:%M:%S'` ERROR:$server_list_file NOT exists!" >>$web_stat_log
exit 1
fi
#total=`wc -l $server_list_file|awk '{print $1}'`
for mysqlserver in `cat $server_list_file`
do
	mysql -h$mysqlserver -u$username -p$password ad_platform -e "SELECT VERSION();" >> /dev/null 2>&1
	if [ $? -eq 0 ] ; then
		echo "`date '+%Y-%m-%d %H:%M:%S'` mysql $mysqlserver monitor status running" >> $mysql_stat_log
	else
		echo "`date '+%Y-%m-%d %H:%M:%S'` mysql $mysqlserver monitor status stoped" >> $mysql_stat_log
		echo "`date '+%Y-%m-%d %H:%M:%S'` mysql $mysqlserver monitor status stoped" | mail -s "mysql $mysqlserver" $mails
	fi
done
exit 0
